package com.woniuxy.education.mapper;

import com.woniuxy.education.entity.*;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MarkTestsMapper {

    /**
     * 查询未批改作业
     *
     * @return
     */
    //通过uid查教师id
    @Select("SELECT id FROM teacher WHERE u_id=#{userid} ")
    String selectteacherid(String userid);

    //通过教师id查班级ID和科目
    @Select("SELECT * FROM tea_class WHERE t_id=#{tid} ")
    List<TeacherClass> selectClassIdBytid(String tid);

    //通过班级ID与科目查询作业信息
    @Select("SELECT * FROM homework WHERE c_id=#{c_id} and subject=#{subject}")
    List<HomeworkAssignments> selectWorks(TeacherClass teacherClass);

    //通过作业信息id查作业题目
    @Select("SELECT * FROM homework_titleid WHERE h_id=#{hid} ")
    HomeworkTitle selecthomework(String hid);

    //通过完成作业题目id查学生
    @Select("SELECT * FROM completed_work WHERE h_id=#{hid} and state=1")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "choose_answer", property = "choose_answer"),
            @Result(column = "completion_answer", property = "completion_answer"),
            @Result(column = "answer_questions_answer", property = "answer_questions_answer"),
            @Result(column = "composition_answer", property = "composition_answer"),
            @Result(column = "h_id", property = "h_id"),
            @Result(column = "u_id", property = "student",
                    many = @Many(select = "com.woniuxy.education.mapper.MarkTestsMapper.selectStudent")),
    })
    List<Completed_work> selectStudents(int homeworkTitleId);

    //查询学生通过uid
    @Select("SELECT * FROM student WHERE u_id=#{uid} ")
    Student selectStudent(String uid);

    //查uid,通过完成作业id
    @Select("SELECT u_id FROM completed_work WHERE id=#{titleid} ")
    Integer finduid(int titleid);
    //查询选择题，通过id
    @Select("SELECT * FROM choose_table WHERE id=#{chooseid} ")
    Choose_table findchooseAnswer(String chooseid);
    /**
     * 批改作业
     */
    //查询学生答案和题目,通过学生完成作业答案id
    @Select("SELECT * FROM completed_work WHERE id=#{hid} ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "choose_answer", property = "choose_answer"),
            @Result(column = "completion_answer", property = "completion_answer"),
            @Result(column = "answer_questions_answer", property = "answer_questions_answer"),
            @Result(column = "composition_answer", property = "composition_answer"),
            @Result(column = "u_id", property = "u_id"),
            @Result(column = "h_id", property = "homeworkTitle",
                    many = @Many(select = "com.woniuxy.education.mapper.MarkTestsMapper.findTitle")),
    })
    Completed_work selectStudentCompletedWorkAndTitle(int homeworkTitleId);

    //查询指定题目id
    @Select("SELECT * FROM homework_titleid WHERE id=#{hid} ")
    HomeworkTitle findTitle(String hid);


    /**
     * 查询未批改试卷
     *
     * @return
     */
    //通过班级ID与科目查询试卷信息
    @Select("SELECT * FROM test_table WHERE c_id=#{c_id} and subject=#{subject}")
    List<TestMessage> selectTestTable(TeacherClass teacherClass);

    //通过试卷信息id查试卷题目
    @Select("SELECT * FROM test_titleid WHERE t_id=#{tid} ")
    Titleids selectTesttitle(String tid);

    //通过完成试卷题目id查学生
    @Select("SELECT * FROM completed_test WHERE t_id=#{tid} and state=1 ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "choose_answer", property = "choose_answer"),
            @Result(column = "completion_answer", property = "completion_answer"),
            @Result(column = "answer_questions_answer", property = "answer_questions_answer"),
            @Result(column = "composition_answer", property = "composition_answer"),
            @Result(column = "t_id", property = "t_id"),
            @Result(column = "u_id", property = "student",
                    many = @Many(select = "com.woniuxy.education.mapper.MarkTestsMapper.selectStudent")),
    })
    List<Completed_test> selectStudentTests(int testTitleId);


    /**
     * 批改试卷
     */
    //查询学生考试答案和题目,通过学生完成试卷答案id
    @Select("SELECT * FROM completed_test WHERE id=#{tid} ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "choose_answer", property = "choose_answer"),
            @Result(column = "completion_answer", property = "completion_answer"),
            @Result(column = "answer_questions_answer", property = "answer_questions_answer"),
            @Result(column = "composition_answer", property = "composition_answer"),
            @Result(column = "u_id", property = "u_id"),
            @Result(column = "t_id", property = "titleids",
                    many = @Many(select = "com.woniuxy.education.mapper.MarkTestsMapper.findTestTitle")),
    })
    Completed_test selectStudentCompletedTestAndTitle(int completedtestId);

    //查询指定考试题目id
    @Select("SELECT * FROM test_titleid WHERE id=#{tid} ")
    Titleids findTestTitle(String tid);


}
